﻿namespace Bigway.Common.Models.DtoModels;

public class ErrorDto
{
    public ErrorCode Code { get; set; } = ErrorCode.Success;
    public string? Message { get; set; }
    public string? UserMessage { get; set; }

    public static readonly ErrorDto Success = new ErrorDto();
}

public enum ErrorCode
{
    Success = 200,
    InvalidRequest = 400,
    Unauthorized = 401,
    InvalidDateRange = 412,
    InvalidAddress = 413,
    InvalidUser = 414,

    EntityNotFound = 420,
    EntityDeleted = 421,
    
    UserSignUpFailed = 422,

    InternalError = 500,
    ConsumeCodeExpired = 601,
    ConsumeCodeNotActiveYet = 602,
    UserNameOrPasswordIncorrect = 611,
    MerchantAlreadyOnboardedToAnotherBusinessCircle = 612,
    BusinessCircleHasMerchants = 613,
    RefererFeeBalanceNotEnough = 614,
    OrderNoAlreadyLinked = 615,
    IssuedBenefitsCardAlreadyLinked = 616,
    BenefitsCardAndIssuedBenefitsCardMismatch = 617,
    IssuedBenefitsCardIdAndCardNoMismatch = 618,
    IssuedBenefitsCardUserAndBuyerMismatch = 619,

    VoucherAlreadyUsed = 620,

    SystemNotSupported = 700
}

public static class ErrorResponse
{
    public static T Create<T>(ErrorCode code, string message, string userMessage)
        where T: BaseResponseDto, new() =>
        Create<T>(new ErrorDto
        {
            Code = code,
            Message = message,
            UserMessage = userMessage
        });

    public static T Create<T>(ErrorDto error)
        where T : BaseResponseDto, new() =>
        new()
        {
            Error = error
        };
}